<template>
  <div class="bg">
    <div class="nav">
      <van-notice-bar
        left-icon="volume-o"
        text="发热病人请先到发热门诊筛查后方可就诊。"
      />
    </div>

    <div class="choice-time">
      <div class="first" @click="alldate()">
        <div>全部</div>
        <div>日期</div>
      </div>
      <div class="time-content">
        <ul>
          <li
            v-for="(day, index) in dayList"
            :key="index"
            @click="dayColor(index, day.isHasSource)"
            :class="{ bgColorChange: morningTime == index }"
          >
            <div class="ename">{{ day.week }}</div>
            <div class="num-name">
              {{ day.date.substring(5, 10) }}
            </div>
            <div class="Number" v-if="day.isHasSource > 0">有号</div>
            <div class="Number2" v-else>无号</div>
          </li>
        </ul>
      </div>
    </div>
    <div
      class="doctor-message"
      v-for="(item, index) in message"
      :key="item.departmentName"
    >
      <div class="message-title" @click="info(item.doctorId)">
        <div class="logo" v-if="item.avatar">
          <img :src="item.avatar" alt="" />
        </div>
        <div class="logo" v-else>
          <img src="../../../../assets/img/main/yisheng.png" alt="" />
        </div>
        <div class="message-some">
          <div class="message-head">
            <span class="name">{{ item.doctorName }}</span>
            <span class="leval">{{ item.doctorTitle }}</span>
          </div>
          <div class="appointment">预约量：{{ item.ghnum }}</div>
          <div class="begood">擅长：{{ item.goodAt }}</div>
        </div>
        <div class="more">更多></div>
      </div>
      <div class="line"></div>
      <div
        class="time-message"
        v-for="itam in message[index].treatTimeData.slice(0, 2)"
        :key="itam.sourceId"
      >
        <div class="cellTime" @click="godorcoinfoo(itam, item)">
          <div class="cellLeft">
            {{ itam.treatDate[5] }}{{ itam.treatDate[6] }}{{ itam.treatDate[7]
            }}{{ itam.treatDate[8] }}{{ itam.treatDate[9] }}{{ itam.treatWeek
            }}{{ itam.sourceTypeName }}
          </div>
          <div class="cellRight">
            余号{{ itam.leftNum }} <span class="spr">></span>
          </div>
        </div>
        <div class="line"></div>
      </div>

      <div
        class="loogMore"
        @click="loogMore(index)"
        v-if="message[index].treatTimeData.length > 2 && treatDate == ''"
      >
        查看更多
      </div>
      <div></div>
      <van-popup
        v-model="show"
        closeable
        :lock-scroll="false"
        position="bottom"
        :style="{ height: '80%' }"
      >
        <div style="margin-bottom:0.3rem;">
          <div class="popup-title">{{ logLeft }}({{ logRight }})</div>
          <div class="line"></div>
          <div>
            <div
              class="work-time"
              v-for="itam in datelist.treatTimeData"
              :key="itam.sourceId"
              @click="godocaaa(itam)"
            >
              <div class="cellLeft">
                {{ itam.treatDate }}
                {{ itam.treatWeek }}{{ itam.sourceTypeName }}
              </div>
              <div class="cellRight">余号{{ itam.leftNum }}</div>
            </div>
          </div>
        </div>
      </van-popup>
    </div>
  </div>
</template>
<script>
import { getDoctListDateApi, getDoctListByDateApi } from "@/service/api.js";
import { loginByWxOpenidApi } from "@/service/api.js";

import { Collapse, CollapseItem, Toast, Dialog } from "vant";
import { Popup } from "vant";
import { Overlay } from "vant";
import { SwipeCell } from "vant";
import { NoticeBar } from "vant";

export default {
  name: "index",
  inject: ["reload"],

  data() {
    return {
      datelist: [],
      logLeft: "",
      logRight: "",
      head: true,
      accordion: true,
      morning: "请选择日期", //上午
      afternoon: "请选择日期", //下午
      morningTime: "-1",
      colordispaly: 100,
      colordispalyAfter: 100,
      show: false,
      departmentId: "", //科室id
      departmentName: "", //科室名称
      hospitalId: "", //医院id
      doctorId: "",
      treatDate: "",
      apptoken: "",
      token: "",
      departmentId: "",
      introduce: [
        {
          title: "妇科门诊简介",
          content:
            "妇科是医疗机构的一个诊疗科目，妇科是妇产科的一个分支专业，是以诊疗女性妇科病为诊疗的专业科室，分为西医妇科与中医妇科。妇科疾病包括:女性生殖系统的疾病即为妇科疾病，包括外阴疾病、阴道疾病、子宫疾病、输卵管疾病、卵巢疾病等"
        }
      ],
      message: [],
      timeListAfter: [],
      dayList: [],
      docidd: ""
    };
  },
  components: {},
  created() {
    (this.apptoken = JSON.parse(localStorage.getItem("apptoken"))),
      // 拿取token
      (this.token = localStorage.getItem("token")),
      (this.departmentId = this.$route.query.departmentId);

    if (this.departmentId) {
    } else {
      this.departmentId = JSON.parse(localStorage.getItem("departmentId"));
    }
    (this.departmentName = JSON.parse(localStorage.getItem("departmentName"))),
      (this.hospitalId = JSON.parse(localStorage.getItem("hosid")));
    if (this.hospitalId) {
      console.log(this.hospitalId);
    } else {
      this.hospitalId = this.$route.query.hospitalId;
      let hosid = JSON.stringify(this.hospitalId);
      localStorage.setItem("hosid", hosid);
    }

    this.getdoctor();
    this.getdayList();
  },
  methods: {
    godocaaa(item) {
      this.show = false;
      let sourceId = item.sourceId;
      let treatDate = item.treatDate;
      let departmentId = JSON.stringify(this.departmentId);
      localStorage.setItem("departmentId", departmentId);
      this.$router.push({
        name: "doctor_info",
        query: {
          doctorId: this.doctorId,
          departmentId: this.departmentId,
          sourceId: sourceId,
          treatDate: treatDate
        }
      });
    },
    godorcoinfoo(itam, item) {
      this.doctorId = item.doctorId;
      let sourceId = itam.sourceId;
      let treatDate = itam.treatDate;
      let departmentId = JSON.stringify(this.departmentId);
      localStorage.setItem("departmentId", departmentId);
      this.$router.push({
        name: "doctor_info",
        query: {
          doctorId: this.doctorId,
          departmentId: this.departmentId,
          sourceId: sourceId,
          treatDate: treatDate
          // departmentName: this.departmentName,
        }
      });
      // console.log(this.docidd);
    },
    // 获取医生日历集合
    getdayList() {
      getDoctListDateApi({
        hospitalId: this.hospitalId,
        departmentId: this.departmentId,
        apptoken: this.apptoken,
        token: this.token
      }).then(res => {
        if (res.code == 4000) {
          this.dayList = res.data;
        } else {
          Toast(res.msg);
        }
      });
    },
    //全部日期
    alldate() {
      //  location.reload();
      this.morningTime = "-1";
      this.treatDate = "";
      this.getdoctor();
    },
    // 改变日期颜色
    dayColor(e, num) {
      this.morning =
        this.dayList[e].date + "(" + this.dayList[e].week + ")" + "上午";
      this.afternoon =
        this.dayList[e].date + "(" + this.dayList[e].week + ")" + "下午";
      // 获取对应日期医生
      this.treatDate = this.dayList[e].date;
      console.log(this.treatDate);
      if (num == 1) {
        this.morningTime = e;
        this.getdoctor();
      }
    },
    //获取医生列表
    getdoctor() {
      getDoctListByDateApi({
        departmentId: this.departmentId,
        treatDate: this.treatDate,
        hospitalId: this.hospitalId,
        apptoken: this.apptoken,
        token: this.token
      }).then(res => {
        if (res.code == 4000) {
          this.message = res.data.list;
        }
      });
    },
    // 改变颜色
    changefirst(id) {
      this.colordispaly = id;
    },
    change(index) {
      this.colordispalyAfter = index;
    },
    // 去详情
    info(id) {
      console.log(id);
      this.doctorId = id;
      let doctorid = JSON.stringify(this.doctorId);
      localStorage.setItem("doctorid", doctorid);
      let departmentId = JSON.stringify(this.departmentId);
      localStorage.setItem("departmentId", departmentId);
      this.$router.push({
        name: "doctor_info",
        query: {
          doctorId: this.doctorId,
          departmentId: this.departmentId
        }
      });
    },
    loogMore(e) {
      console.log(e);
      this.show = true;
      this.logLeft = this.message[e].doctorName;
      this.logRight = this.message[e].doctorTitle;
      this.doctorId = this.message[e].doctorId;
      this.datelist = this.message[e];
      console.log(this.logLeft);
    }
  }
};
</script>
<style lang="scss" scoped>
.work-time {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-left: 10px;
  margin-right: 10px;
  height: 1rem;
  overflow: auto;
}
.cellLeft {
  font-size: 0.38rem;
  font-family: PingFang SC;
  font-weight: 500;
  color: #333333;
  line-height: 21px;
}
.cellRight {
  font-size: 0.4rem;
  font-family: PingFang SC;
  font-weight: 500;
  color: #07c6b4;
  line-height: 1rem;
  // margin-right: 10px;
  font-weight: bold;
  .spr {
    color: #bbbbbb;
  }
}
.van-cell__value {
  color: #07c6b4 !important;
}
.popup-title {
  margin-top: 0.2rem;
  margin-bottom: 0.4rem;
  text-align: center;
  font-size: 0.45rem;
  font-family: PingFang SC;
  font-weight: 500;
  color: #333333;
}
.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}
.block {
  width: 80%;
  height: 50%;
  background-color: #fff;
  overflow: auto;
  border-radius: 0.1rem;
  .block-title {
    font-size: 0.35rem;
    font-family: PingFang SC;
    font-weight: bold;
    color: #000000;
    line-height: 0.5rem;
    text-align: center;
    margin-top: 0.3rem;
    margin-bottom: 0.1rem;
  }
  .block-message {
    font-size: 0.35rem;
    font-family: PingFang SC;
    font-weight: 500;
    color: #999999;
    line-height: 0.5rem;
    margin-left: 0.3rem;
    margin-right: 0.3rem;
    margin-bottom: 0.1rem;
  }
}
.nav {
  margin-top: 1rem;
}
.bg {
  width: 100%;
  // height: 100%;
  background: #f6f6f6;
  overflow-y: auto;
  // padding-bottom: 100vh;
  .hot {
    width: 99%;
    height: 35px;
    background: #fffbe6;
    border: 1px solid #fbb62e;
    display: flex;
    // padding-left: 35px;
    .logo {
      width: 20px;
      height: 20px;
      margin-left: 10px;
      margin-top: 2px;
      margin-right: 10px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .hot-title {
      font-size: 13px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #fbb62e;
      line-height: 35px;
    }
  }
  .choice-time {
    overflow: auto;
    background-color: #ffffff;
    display: flex;
    align-items: center;
    margin-bottom: 0.2rem;
    height: 2rem;
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
    .first {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 1.8rem;
      height: 2rem;
      background: #07c6b4;
      border-radius: 0.1rem;
      margin-left: 0.2rem;
      margin-right: 0.1rem;
      font-size: 0.35rem;
      font-weight: bold;
      color: #ffffff;
    }
    .time-content {
      overflow: auto;
      width: 100%;
      ul {
        overflow: auto;
        display: flex;
        overflow-x: auto;
        .bgColorChange {
          background: #07c6b4;
          color: #ffffff;
        }
        li {
          // display: inline-block;
          width: 1.5rem;
          height: 2rem;
          background: #f5f5f7;
          border-radius: 0.1rem;
          text-align: center;
          margin-right: 0.2rem;
          .ename {
            font-size: 0.3rem;
            font-family: PingFang SC;
            font-weight: 500;
            line-height: 0.65rem;
          }
          .num-name {
            width: 1.5rem;
            font-size: 0.3rem;
            font-family: PingFang SC;
            font-weight: 500;
            line-height: 0.6rem;
          }
          .Number {
            width: 1rem;
            height: 0.45rem;
            background: #ffffff;
            border-radius: 0.1rem;
            text-align: center;
            line-height: 0.45rem;
            color: #07c6b4;
            margin: 0.1rem auto;
            font-size: 0.3rem;
          }
          .Number2 {
            width: 1rem;
            height: 0.45rem;
            background: #ffffff;
            border-radius: 0.1rem;
            text-align: center;
            line-height: 0.45rem;
            color: #cccccc;
            margin: 0.1rem auto;
            font-size: 0.3rem;
          }
        }
      }
    }
  }

  .line {
    width: 10rem;
    border-bottom: 0.05rem solid #f6f6f6;
    margin: 0 auto;
    // margin-top: 0.2rem;
  }
  .doctor-message {
    width: 100%;
    background-color: #ffffff;
    margin-bottom: 0.2rem;
    .message-title {
      width: 100%;
      display: flex;
      padding-bottom: 0.2rem;
      .logo {
        width: 1.2rem;
        height: 1.2rem;
        border-radius: 50%;
        margin-left: 0.2rem;
        margin-right: 0.2rem;
        margin-top: 0.3rem;
        img {
          width: 1.2rem;
          height: 1.2rem;
          border-radius: 50%;
        }
      }
      .message-some {
        .message-head {
          margin-bottom: 0.1rem;
          margin-top: 0.2rem;
          .name {
            font-size: 0.45rem;
            font-family: PingFang SC;
            font-weight: 500;
            color: #333333;
            margin-right: 0.1rem;
            font-weight: bold;
          }
          .leval {
            font-size: 0.3rem;
            font-family: PingFang SC;
            font-weight: 500;
            color: #333333;
          }
        }
        .appointment {
          font-size: 0.3rem;
          font-family: PingFang SC;
          font-weight: 500;
          color: #666666;
          margin-bottom: 0.1rem;
        }
        .begood {
          width: 7rem;
          font-size: 0.3rem;
          font-family: PingFang SC;
          font-weight: 500;
          color: #666666;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
      .more {
        font-size: 0.3rem;
        font-family: PingFang SC;
        font-weight: 500;
        color: #666666;
        margin-top: 0.8rem;
        margin-left: 0.3rem;
      }
    }
    .time-message {
      .cellTime {
        display: flex;
        justify-content: space-between;
        // align-items: center;
        margin-left: 0.2rem;
        margin-right: 0.2rem;
        height: 1.3rem;
        .cellLeft {
          font-size: 0.4rem;
          font-family: PingFang SC;
          font-weight: 500;
          color: #333333;
          line-height: 1.3rem;
        }
        .cellRight {
          font-size: 0.4rem;
          font-family: PingFang SC;
          font-weight: 500;
          color: #07c6b4;
          line-height: 1.3rem;
          margin-right: 0.2rem;
        }
      }
    }
    .loogMore {
      width: 100%;
      height: 0.8rem;
      text-align: center;
      line-height: 0.8rem;
      color: #07c6b4;
      font-size: 0.35rem;
      font-family: PingFang SC;
      font-weight: 500;
    }
  }
}
</style>
